home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** Demonstration of sound format conversion support in Sound Manager 3.2
- **
- ** by Andrew Wulf, Apple Developer Technical Support
- **
- ** File: SoundConvert.c
- **
- ** Copyright © 1996 Apple Computer, Inc.
- ** All rights reserved.
- **
- ** You may incorporate this sample code into your applications without
- ** restriction, though the sample code has been provided "AS IS" and the
- ** responsibility for its operation is 100% yours. However, what you are
- ** not permitted to do is to redistribute the source as "DSC Sample Code"
- ** after having made changes. If you're going to re-distribute the source,
- ** we require that you make it clear in the source that the code was
- ** descended from Apple Sample Code, but that you've made changes.
- */
-
- #include <Quickdraw.h>
- #include <Windows.h>
- #include <Dialogs.h>
- #include <Files.h>
- #include <StandardFile.h>
- #include <Packages.h>
- #include <OSEvents.h>
- #include <Memory.h>
- #include <OSUtils.h>
- #include <ToolUtils.h>
- #include <Types.h>
- #include <TextUtils.h>
- #include <SegLoad.h>
- #include <Gestalt.h>
- #include <AIFF.h>
- #include <stdio.h>
- #include <strings.h>
- #include <string.h>
- // the following are from sound manager 3.2, not yet in ETO 19
- #include <Sound.h>
- #include <SoundComponents.h>
- #include <SoundInput.h>
-
- #define FormatPopupMenu 128
- #define RatePopupMenu 129
- #define DialogID 129
-
- enum {
- Button_Quit = 1,
- Button_Input = 3,
- Button_Convert,
- Static_Filename,
- Radio_8bit,
- Radio_16bit,
- Radio_Mono,
- Radio_Stereo,
- Popup_Format,
- Popup_Rate,
- Static_Notes = 13
- };
-
- typedef struct
- {
- FSSpec file;
- SoundComponentData info;
- unsigned long numFrames;
- unsigned long dataOffset;
- Ptr buffer;
- } SoundFileInfo;
-
- typedef struct
- {
- FSSpec file;
- SoundComponentData info;
- unsigned long inputBufferFrames;
- unsigned long inputBufferBytes;
- unsigned long outputBytes;
- Ptr buffer;
- } SoundConvertInfo;
-
- typedef struct
- {
- OSType formatType;
- Boolean isCompressor;
- Boolean isDecompressor;
- short dummy;
- } MenuToFormatType, *MenuToFormatTypePtr, **MenuToFormatTypeHandle;
-
- MenuToFormatTypeHandle MenuToFormatTypeList = 0; // used to map menu to format type
- short Group1;
- short Group2;
- Point Where;
- short Modifiers;
- SoundFileInfo FileInfo = { 0, 0, "\p" };
- long BuffersSize= 0;
-
- #define LAST_SAMPLE_MENU 5
- Fixed MenuToSampleRates[LAST_SAMPLE_MENU]
- = { rate44khz, rate22050hz, rate22khz, rate11khz, rate11025hz };
-
- #if ((!defined(__MWERKS__))&&(!defined(THINK_C)))
- QDGlobals qd;
- #endif
-
- OSErr ShowErr(char*text, short err);
- void ShowErrAndQuit(char*text, short err);
- void BuildFormatMenu(void);
- void SetRadio(DialogPtr dlog, short item, short val);
- short GetRadio(DialogPtr dlog, short item);
- pascal Boolean MyFilter( DialogPtr, EventRecord *, short *);
- DialogPtr OpenDialog(void);
- void RunDialog(DialogPtr dialog);
- void DoDialogUpdate( DialogPtr dialog);
- void ShowAControl( DialogPtr dlog, short item );
- Boolean GetInputFile(void);
- void DoConversion( DialogPtr dialog );
- void ShowInfo( DialogPtr dialog );
- void SetStaticText( DialogPtr dlog, short item, Byte* s );
- void MakeInfoString( SoundFileInfo*info, Byte* s );
- void GetWantedData(DialogPtr dialog, SoundComponentData* info);
- short GetAControlValue(DialogPtr dlog, short item);
- OSErr ConvertSound( SoundFileInfo*, SoundConvertInfo*, SoundConverter sc );
- void HiliteAControl( DialogPtr dlog, short item, Boolean state );
- OSErr ConvertBufferInMemory( SoundFileInfo*input, short inputFile,
- SoundConvertInfo*output, short outputFile, SoundConverter sc );
- OSErr ConvertBufferInChunks( SoundFileInfo*input, short inputFile,
- SoundConvertInfo*output, short outputFile, SoundConverter sc );
-
- // ----------------------------------------------------------------------------------
-
- void main()
- {
- NumVersion version;
- DialogPtr dialog;
-
- MaxApplZone();
-
- InitGraf(&qd.thePort);
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitDialogs(0);
- InitCursor();
-
- version = SndSoundManagerVersion();
- if ( ! ( version.majorRev >= 3 && version.minorAndBugRev >= 0x20 ) )
- ShowErrAndQuit( "Sound Manager is older than 3.2", 0 );
-
- dialog = OpenDialog();
- if ( dialog )
- RunDialog(dialog);
- }
-
- // Create our one and only dialog
-
- DialogPtr OpenDialog()
- {
- DialogPtr dialog;
-
- InsertMenu(GetMenu(FormatPopupMenu),-1);
- InsertMenu(GetMenu(RatePopupMenu),-1);
- BuildFormatMenu();
-
- dialog = GetNewDialog( DialogID, 0, (WindowPtr)(-1L) );
- SetPort(dialog);
-
- SetRadio( dialog, Group1 = Radio_8bit, 1);
- SetRadio( dialog, Radio_16bit, 0);
- SetRadio( dialog, Group2 = Radio_Mono, 1);
- SetRadio( dialog, Radio_Stereo, 0);
-
- ShowAControl( dialog, Popup_Format );
- ShowAControl( dialog, Popup_Rate );
-
- HiliteAControl( dialog, Button_Convert, false );
-
- ShowWindow(dialog);
-
- return dialog;
- }
-
- // Execute dialog until quit button hit
-
- void RunDialog( DialogPtr dialog )
- {
- Boolean keepGoing = true;
- short itemHit;
- ModalFilterUPP filter = NewModalFilterProc( MyFilter );
-
- while (keepGoing)
- {
- ModalDialog( filter, &itemHit );
-
- switch( itemHit )
- {
- case Button_Quit:
- keepGoing = false;
- break;
-
- case Button_Input:
- if ( GetInputFile() )
- HiliteAControl( dialog, Button_Convert, true );
- ShowInfo( dialog );
- break;
-
- case Button_Convert:
- DoConversion( dialog );
- break;
-
- case Radio_8bit:
- case Radio_16bit:
- if ( itemHit != Group1 )
- {
- SetRadio( dialog, Group1, 0 );
- Group1 = ( Group1 == Radio_8bit ) ? Radio_16bit : Radio_8bit;
- SetRadio( dialog, Group1, 1 );
- }
- break;
-
- case Radio_Mono:
- case Radio_Stereo:
- if ( itemHit != Group2 )
- {
- SetRadio( dialog, Group2, 0 );
- Group2 = ( Group2 == Radio_Mono ) ? Radio_Stereo : Radio_Mono;
- SetRadio( dialog, Group2, 1 );
- }
- break;
-
- case Popup_Format:
- case Popup_Rate:
- break;
- }
- }
- }
-
- // Get a file to work on
-
- Boolean GetInputFile()
- {
- StandardFileReply reply;
- SFTypeList types = { 'AIFF', 'AIFC', 0, 0 };
-
- StandardGetFile( 0L, 2, types, &reply );
- if ( reply.sfGood )
- FileInfo.file = reply.sfFile;
-
- return FileInfo.file.name[0] != 0;
- }
-
- // Pick an output file and convert it
-
- void DoConversion( DialogPtr dialog )
- {
- StandardFileReply reply;
- Str63 s, t;
-
- BlockMove( FileInfo.file.name, s, FileInfo.file.name[0]+1 ); p2cstr(s);
- sprintf( (char*)t, "%s.mod", (char*)s ); c2pstr((char*)t);
- if ( t[0] > 31 )
- t[0] = 31;
-
- StandardPutFile( "\pSave converted sound as:", t, &reply );
- if ( reply.sfGood )
- {
- SoundConvertInfo convertInfo;
- SoundConverter sc;
- OSErr err;
-
- convertInfo.file = reply.sfFile;
- GetWantedData( dialog, &convertInfo.info );
-
- err = SoundConverterOpen( &FileInfo.info, &convertInfo.info, &sc );
- if ( err )
- ShowErr( "SoundConverterOpen failed", err );
- else
- {
- if ( BuffersSize == 0 )
- {
- BuffersSize = MaxBlock();
- BuffersSize = BuffersSize * 0.4; // try 40% of available space
- }
-
- err = SoundConverterGetBufferSizes( sc, BuffersSize,
- &convertInfo.inputBufferFrames,
- &convertInfo.inputBufferBytes,
- &convertInfo.outputBytes );
- if ( err )
- ShowErr( "SoundConverterGetBufferSizes failed", err );
- else
- ConvertSound( &FileInfo, &convertInfo, sc );
-
- SoundConverterClose(sc);
- }
- }
- }
-
- // Actually convert sound from input to output
-
- OSErr ConvertSound( SoundFileInfo*input, SoundConvertInfo*output, SoundConverter sc )
- {
- OSErr err=0;
- short inputFile=0, outputFile=0;
-
- // make buffers
-
- input->buffer = output->buffer = 0;
-
- input->buffer = NewPtr( output->inputBufferBytes );
- err = MemError();
- if ( err )
- {
- ShowErr( "creating input buffer", err );
- goto CLEANUP;
- }
- output->buffer = NewPtr( output->outputBytes );
- err = MemError();
- if ( err )
- {
- ShowErr( "creating output buffer", err );
- goto CLEANUP;
- }
-
- // open files
-
- err = FSpOpenDF( &input->file, fsCurPerm, &inputFile );
- if ( err )
- {
- ShowErr( "opening input file", err );
- goto CLEANUP;
- }
-
- FSpCreate ( &output->file, 'SCPL', 'AIFC', 0); // a SoundApp creator & filetype
- err = FSpOpenDF( &output->file, fsRdWrPerm, &outputFile );
- if ( err )
- {
- ShowErr( "opening output file", err );
- goto CLEANUP;
- }
- SetEOF( outputFile, 0 );
-
- SoundConverterBeginConversion( sc );
-
- // if it fits in memory, do it in one shot
-
- if ( input->numFrames <= output->inputBufferFrames )
- {
- err = ConvertBufferInMemory( input, inputFile, output, outputFile, sc );
- if ( err )
- goto CLEANUP;
- }
-
- // otherwise convert it in chunks
-
- else
- {
- err = ConvertBufferInChunks( input, inputFile, output, outputFile, sc );
- if ( err )
- goto CLEANUP;
- }
-
- CLEANUP:
-
- if ( input->buffer )
- DisposePtr( input->buffer );
- if ( output->buffer )
- DisposePtr( output->buffer );
- if ( inputFile )
- FSClose( inputFile );
- if ( outputFile )
- FSClose( outputFile );
- FlushVol( "\p", output->file.vRefNum );
-
- return err;
- }
-
- // convert the input buffer when it fits in memory
-
- OSErr ConvertBufferInMemory( SoundFileInfo*input, short inputFile,
- SoundConvertInfo*output, short outputFile, SoundConverter sc )
- {
- unsigned long actualOutputFrames=0;
- unsigned long actualOutputSize=0;
- unsigned long additionalOutputFrames=0;
- unsigned long additionalOutputSize=0;
- long inputFileSize;
- OSErr err;
-
- GetEOF( inputFile, &inputFileSize );
-
- err = SetFPos( inputFile, fsFromStart, input->dataOffset );
- if ( err )
- return ShowErr( "setting position in input file", err );
- inputFileSize -= input->dataOffset;
-
- err = FSRead( inputFile, &inputFileSize, input->buffer );
- if ( err )
- return ShowErr( "reading input file", err );
-
- err = SoundConverterConvertBuffer( sc,
- input->buffer,
- input->numFrames,
- output->buffer,
- &actualOutputFrames,
- &actualOutputSize );
- if ( err )
- return ShowErr( "converting sound", err );
-
- err = SetupAIFFHeader( outputFile,
- output->info.numChannels,
- output->info.sampleRate,
- output->info.sampleSize,
- output->info.format,
- actualOutputSize,
- actualOutputFrames );
- if ( err )
- return ShowErr( "setting AIFF header in file", err );
-
- err = FSWrite( outputFile, (long*)&actualOutputSize, output->buffer );
- if ( err )
- return ShowErr( "writing to output file", err );
-
- // end the conversion, and see if you get back a few more bytes of data
-
- err = SoundConverterEndConversion( sc, output->buffer,
- &additionalOutputFrames, &additionalOutputSize );
- if ( err )
- return ShowErr( "ending conversion", err );
-
- // if we got a dribble more, write it to disk, then update header
-
- if ( additionalOutputFrames )
- {
- SysBeep(1);
- err = FSWrite( outputFile, (long*)&additionalOutputSize, output->buffer );
- if ( err )
- return ShowErr( "2nd writing to output file", err );
-
- err = SetFPos(outputFile, fsFromStart, 0);
- if ( err )
- return ShowErr( "setting file position to 0", err );
-
- err = SetupAIFFHeader( outputFile,
- output->info.numChannels,
- output->info.sampleRate,
- output->info.sampleSize,
- output->info.format,
- actualOutputSize+additionalOutputSize,
- actualOutputFrames+additionalOutputFrames );
- if ( err )
- return ShowErr( "2nd setting AIFF header in file", err );
- }
-
- return 0;
- }
-
- // convert a sound file that's too big to convert in memory at once
-
- OSErr ConvertBufferInChunks( SoundFileInfo*input, short inputFile,
- SoundConvertInfo*output, short outputFile, SoundConverter sc )
- {
- OSErr err;
- long inputFileSize;
- long currentFrames, framesLeft=input->numFrames;
- long bytesRead;
- long byteWritten=0, framesWritten=0;
- unsigned long actualOutputFrames=0;
- unsigned long actualOutputSize=0;
- unsigned long additionalOutputFrames=0;
- unsigned long additionalOutputSize=0;
-
- // setup input file for reading
-
- GetEOF( inputFile, &inputFileSize );
- err = SetFPos( inputFile, fsFromStart, input->dataOffset );
- if ( err )
- return ShowErr( "setting position in input file", err );
- inputFileSize -= input->dataOffset;
-
- // setup dummy header ( we'll update when done )
-
- err = SetupAIFFHeader( outputFile,
- output->info.numChannels,
- output->info.sampleRate,
- output->info.sampleSize,
- output->info.format,
- 0,
- 0 );
- if ( err )
- return ShowErr( "setting AIFF header in file", err );
-
- currentFrames = output->inputBufferFrames;
-
- // loop through buffers of size = output->inputBufferFrames
-
- while ( framesLeft > 0 )
- {
- // read a buffer full from input file
-
- bytesRead = output->inputBufferBytes;
- err = FSRead( inputFile, &bytesRead, input->buffer );
- if ( err != 0 && err != -39 )
- return ShowErr( "reading input file", err );
-
- // convert the buffer
-
- err = SoundConverterConvertBuffer( sc,
- input->buffer,
- currentFrames,
- output->buffer,
- &actualOutputFrames,
- &actualOutputSize );
- if ( err )
- return ShowErr( "converting sound buffer", err );
-
- // write the result to output file
-
- err = FSWrite( outputFile, (long*)&actualOutputSize, output->buffer );
- if ( err )
- return ShowErr( "writing sound buffer to file", err );
-
- byteWritten += actualOutputSize;
- framesWritten += actualOutputFrames;
-
- // calculate remaining frames and adjust currentFrames for last buffer
-
- framesLeft -= currentFrames;
- if ( framesLeft < output->inputBufferFrames )
- currentFrames = framesLeft;
- }
-
- // end the conversion, and see if you get back a few more bytes of data
-
- err = SoundConverterEndConversion( sc, output->buffer,
- &additionalOutputFrames, &additionalOutputSize );
- if ( err )
- return ShowErr( "ending conversion", err );
-
- // if we got a dribble more, write it to disk, then update header
-
- if ( additionalOutputFrames )
- {
- err = FSWrite( outputFile, (long*)&additionalOutputSize, output->buffer );
- if ( err )
- return ShowErr( "2nd writing to output file", err );
- }
-
- err = SetFPos(outputFile, fsFromStart, 0);
- if ( err )
- return ShowErr( "setting file position to 0", err );
-
- err = SetupAIFFHeader( outputFile,
- output->info.numChannels,
- output->info.sampleRate,
- output->info.sampleSize,
- output->info.format,
- byteWritten+additionalOutputSize,
- framesWritten+additionalOutputFrames );
- if ( err )
- return ShowErr( "2nd setting AIFF header in file", err );
-
- return 0;
- }
-
- // Get and show info of current input file
-
- void ShowInfo( DialogPtr dialog )
- {
- SetStaticText( dialog, Static_Filename, FileInfo.file.name );
- SetStaticText( dialog, Static_Notes, "\p" );
-
- if ( FileInfo.file.name[0] != 0 )
- {
- short fileRef;
- Str255 s;
-
- OSErr err = FSpOpenDF( &FileInfo.file, fsCurPerm, &fileRef );
- if ( err )
- {
- ShowErr( "opening input file", err );
- goto PUNT;
- }
-
- err = ParseAIFFHeader( fileRef, &FileInfo.info, &FileInfo.numFrames, &FileInfo.dataOffset );
-
- FSClose( fileRef );
-
- if ( err )
- {
- ShowErr( "reading AIFF header", err );
- goto PUNT;
- }
-
- MakeInfoString( &FileInfo, s );
- SetStaticText( dialog, Static_Notes, s );
- return;
- }
- PUNT:
- SetStaticText( dialog, Static_Notes, "\p" );
- }
-
- // Set a SoundComponentData with current dialog settings
-
- void GetWantedData(DialogPtr dialog, SoundComponentData* info)
- {
- short formatPopupIndex = GetAControlValue( dialog, Popup_Format );
- short ratePopupIndex = GetAControlValue( dialog, Popup_Rate );
- short isMono = GetRadio( dialog, Radio_Mono );
- short is8Bit = GetRadio( dialog, Radio_8bit );
-
- info->flags = 0;
- info->format = (*MenuToFormatTypeList)[ formatPopupIndex-1 ].formatType;
- info->numChannels = isMono ? 1 : 2;
- info->sampleSize = is8Bit ? 8 : 16;
- info->sampleRate = MenuToSampleRates[ ratePopupIndex-1 ];
- info->sampleCount = 0;
- info->buffer = 0;
- info->reserved = 0;
- }
-
- // build a string describing the current file
-
- void MakeInfoString( SoundFileInfo* fileInfo, Byte* s )
- {
- char stereoString[16], sampleSizeString[8], sampleRateString[16], formatString[64];
- double_t samplesPerSec;
- short i, n;
- Fixed f = fileInfo->info.sampleRate & 0x80000000L;
-
- if ( fileInfo->info.numChannels >= 2 )
- strcpy( stereoString, "stereo" );
- else
- strcpy( stereoString, "mono" );
-
- sprintf( sampleSizeString, "%hd bit", fileInfo->info.sampleSize );
-
- samplesPerSec = Fix2X( fileInfo->info.sampleRate & 0x7fffffffL ); // unsigned Fixed value
- if ( f )
- samplesPerSec += 32768.0;
- sprintf( sampleRateString, "%.3lf", samplesPerSec/1000.0 );
-
- n = GetHandleSize( (Handle) MenuToFormatTypeList ) / sizeof( MenuToFormatType );
- for ( i=0; i<n; i++ )
- if ( (*MenuToFormatTypeList)[i].formatType == fileInfo->info.format )
- {
- GetMenuItemText( GetMHandle( FormatPopupMenu ), i+1, (Byte*)formatString );
- p2cstr( (Byte*)formatString );
- break;
- }
- if ( i == n )
- strcpy( formatString, "unknown" );
-
- sprintf( (char*)s, "File has %s %s sound, recorded at %s khz, with a format of “%s.”",
- sampleSizeString, stereoString, sampleRateString, formatString );
- c2pstr( (char*)s );
- }
-
- // Find all compressor components and add them to the format popup
-
- void BuildFormatMenu(void)
- {
- Component component=0;
- ComponentDescription desc, info;
- Handle name = NewHandle(0);
- MenuHandle menu = GetMHandle( FormatPopupMenu );
- short compCount=3, i;
-
- MenuToFormatTypeList = (MenuToFormatType**)NewHandleClear(3*sizeof(MenuToFormatType));
-
- // add the built in types
-
- (*MenuToFormatTypeList)[0].formatType = kOffsetBinary;
- (*MenuToFormatTypeList)[0].isCompressor =
- (*MenuToFormatTypeList)[0].isDecompressor = true;
-
- (*MenuToFormatTypeList)[1].formatType = kTwosComplement;
- (*MenuToFormatTypeList)[1].isCompressor =
- (*MenuToFormatTypeList)[1].isDecompressor = true;
-
- (*MenuToFormatTypeList)[2].formatType = 0;
-
- // scan through the compressors
-
- desc.componentType = kSoundCompressor;
- desc.componentSubType = 0;
- desc.componentManufacturer = 0;
- desc.componentFlags = 0;
- desc.componentFlagsMask = 0;
-
- while ( ( component = FindNextComponent( component, &desc ) ) != 0 )
- {
- GetComponentInfo( component, &info, name, 0, 0 );
- if ( GetHandleSize(name) )
- {
- MenuToFormatType data;
-
- data.formatType = info.componentSubType;
- data.isCompressor = true;
-
- AppendMenu( menu, "\p " );
- HLock( name );
- SetMenuItemText( menu, CountMItems(menu), (Byte*)*name );
- HUnlock( name );
- PtrAndHand( (Ptr)&data, (Handle)MenuToFormatTypeList, sizeof(MenuToFormatType) );
- compCount++;
- }
- }
-
- // scan through the decompressors
-
- desc.componentType = kSoundDecompressor;
- desc.componentSubType = 0;
- desc.componentManufacturer = 0;
- desc.componentFlags = 0;
- desc.componentFlagsMask = 0;
-
- while ( ( component = FindNextComponent( component, &desc ) ) != 0 )
- {
- GetComponentInfo( component, &info, name, 0, 0 );
- if ( GetHandleSize(name) && info.componentSubType )
- {
- // see if we have a compressor already, and if so, mark it
-
- MenuToFormatTypePtr p = *MenuToFormatTypeList;
- for ( i=0; i<compCount; i++, p++ )
- if ( info.componentSubType == p->formatType )
- {
- p->isDecompressor = true;
- break;
- }
-
- // else create a new entry
-
- if ( i == compCount )
- {
- MenuToFormatType data;
-
- data.formatType = info.componentSubType;
- data.isDecompressor = true;
-
- AppendMenu( menu, "\p " );
- HLock( name );
- SetMenuItemText( menu, CountMItems(menu), (Byte*)*name );
- HUnlock( name );
- PtrAndHand( (Ptr)&data, (Handle)MenuToFormatTypeList, sizeof(MenuToFormatType) );
- }
- }
- }
-
- DisposeHandle( name );
- }
-
- // --------- just some utility routines ---------------------------------------------------
-
- // handle a few items in the dialog
-
- pascal Boolean MyFilter( DialogPtr dialog, EventRecord *evt, short *itemHit )
- {
- WindowPtr w = (WindowPtr)(evt->message);
- Boolean ans = false;
-
- switch(evt->what)
- {
- case updateEvt:
- if ( w == dialog )
- {
- DoDialogUpdate(dialog);
- ans = true;
- *itemHit = 0;
- }
- break;
-
- case mouseDown:
- case mouseUp:
- Where = evt->where;
- GlobalToLocal(&Where);
- Modifiers = evt->modifiers;
- break;
- }
-
- return ans ;
- }
-
- void DoDialogUpdate( DialogPtr dialog)
- {
- GrafPtr oldPort;
-
- GetPort(&oldPort);
- SetPort(dialog);
- BeginUpdate(dialog);
-
- UpdtDialog(dialog,dialog->visRgn);
-
- EndUpdate(dialog);
- SetPort(oldPort);
- }
-
- void SetStaticText( DialogPtr dlog, short item, Byte* s )
- {
- short type;
- Handle hndl;
- Rect box;
-
- GetDialogItem(dlog,item,&type,&hndl,&box);
- SetDialogItemText( hndl, s );
- }
-
- void ShowAControl( DialogPtr dlog, short item )
- {
- short type;
- Handle hndl;
- Rect box;
-
- GetDialogItem(dlog,item,&type,&hndl,&box);
- ShowControl( (ControlHandle)hndl );
- }
-
- void HiliteAControl( DialogPtr dlog, short item, Boolean state )
- {
- short type;
- Handle hndl;
- Rect box;
-
- GetDialogItem(dlog,item,&type,&hndl,&box);
- HiliteControl( (ControlHandle)hndl, state? 0 : 255 );
- }
-
- void SetRadio(DialogPtr dlog, short item, short val)
- {
- short type;
- Handle hndl;
- Rect box;
-
- GetDialogItem(dlog,item,&type,&hndl,&box);
- SetControlValue((ControlHandle)hndl,val!=0);
- }
-
- short GetRadio(DialogPtr dlog, short item)
- {
- short type;
- Handle hndl;
- Rect box;
-
- GetDialogItem(dlog,item,&type,&hndl,&box);
- return GetControlValue((ControlHandle)hndl) != 0;
- }
-
- short GetAControlValue(DialogPtr dlog, short item)
- {
- short type;
- Handle hndl;
- Rect box;
-
- GetDialogItem(dlog,item,&type,&hndl,&box);
- return GetControlValue((ControlHandle)hndl);
- }
-
- OSErr ShowErr(char*text, short err)
- {
- char s[256];
- if (err)
- sprintf((char*)s, "Failure at %s, with error = %hd.", text, err);
- else
- sprintf((char*)s, "%s.", text);
- c2pstr(s);
- ParamText((Byte*)s, 0, 0, 0);
- NoteAlert(128, 0);
- return err;
- }
-
- void ShowErrAndQuit(char*text, short err)
- {
- ShowErr( text, err );
- ExitToShell();
- }
-